/*
 * Copyright 2008 Max Kugland
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.splink.library.reflection {

	/**
	 * Represents meta infomation for methods, accessors and variables
	 * 
	 * @author Max Kugland
	 */
	public class MetaData {
		private var _name : String;
		private var _args : Array;

		/**
		 * @param name the name of the metadata
		 * @param args the arguments of the metadata
		 */
		public function MetaData(name : String, args : Array) {
			_name = name;
			_args = args;
		}

		/**
		 * @return the metadata's name
		 */
		public function getName() : String {
			return _name;
		}

		/**
		 * @return the metadata's arguments as an array of <code>MetaDataArgument</code> instances
		 */
		public function getArgs() : Array {
			return _args;
		}

		/**
		 * @return the values of the metadata's arguments as an array 
		 */
		public function getArgValues() : Array {
			var ar : Array = new Array;
			for each (var arg : MetaDataArgument in _args) {
				ar.push(arg.value);
			}
			return ar;
		}

		/**
		 * @return a <code>MetaDataArgument</code> instance for a given key if it is found. Otherwise
		 * returns null
		 */
		public function getArgForKey(key : String) : MetaDataArgument {
			for each (var arg : MetaDataArgument in _args) {
				if(arg.key == key) return arg;
			}
			return null;
		}
	}
}